package dfs;

import java.util.LinkedList;
import java.util.List;

public class WordDictionary {
    List<String> list=null;
    public WordDictionary() {
        list = new LinkedList<String>();
    }

    public void addWord(String word) {
          list.add(word);
    }

    public boolean search(String word) {
        char[] chars = word.toCharArray();
        for (String s : list) {
            char[] charArray = s.toCharArray();
            int num=0;
            if (charArray.length!=chars.length)
                continue;
            for (int i = 0; i < chars.length; i++) {
                if (chars[i]==charArray[i] || chars[i]=='.')
                    num++;
            }
            return num==chars.length;
        }
        return false;
    }
}
